package com.beone.admin.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.base.SuperServiceImpl;
import com.beone.admin.entity.TaskType;
import com.beone.admin.form.TaskTypeForm;
import com.beone.admin.mapper.TaskTypeMapper;
import com.beone.admin.service.TaskTypeService;
import com.beone.admin.utils.PaginationGatagridTable;
import com.beone.admin.utils.ServiceUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @Title 任务类型表 服务实现类
 * @Author 秦波
 * @Version 1.0 on 2019-05-18
 * @Copyright 贝旺科权
 */
@Service
public class TaskTypeServiceImpl extends SuperServiceImpl<TaskTypeMapper, TaskType> implements TaskTypeService {

    /**
    * 分页显示任务类型表列表
    * @param userId
    * @param currPage  当前页码
    * @param pageSize  每页显示记录数
    * @return
    */
    public PaginationGatagridTable getTaskTypePagination(Integer userId, int currPage, int pageSize){
        EntityWrapper<TaskType> ew = new EntityWrapper<TaskType>();
        Page<TaskType> page = new Page<TaskType>(currPage,pageSize);
        ew.eq("create_user_id", userId);
        List<TaskType> rows = baseMapper.selectPage(page, ew);
        return ServiceUtils.createGatagridTableJson(page,rows);
    }

    @Override
    public boolean insertOrUpdate(TaskTypeForm form) {
        TaskType type = new TaskType();
        BeanUtils.copyProperties(form, type);
        if (form.getId() != null) {
            type.setUpdateTime(new Date());
        } else {
            type.setCreateTime(new Date());
            type.setCreateUserId(form.getUserId());
        }
        return super.insertOrUpdate(type);
    }
}
